package org.jieshen.m1.d8;

import java.util.ArrayList;
import java.util.List;

public class Solution {
    public List<Integer> grayCode(int n) {
        List<Integer> lists = new ArrayList<>();
        lists.add(0);
        int pos = 1;
        for (int i = 0; i < n; i++) {

            for (int j = lists.size() - 1; j >= 0; j--) {
                lists.add(pos + lists.get(j));
            }
            pos <<= 1;
        }
        return lists;
    }

    public static void main(String[] args) {
        List<Integer> arr = new Solution().grayCode(1);
        for (Integer integer : arr) {
            System.out.println(integer);
        }
    }
}
